﻿using System;
using System.Collections.Generic;

using E.BLL;
using E.Model;
using E.Web.UI.Page;
using E.Enum;

using X.Common;
using System.Text;

namespace E.Web.Teacher.exam
{
    public partial class ExamDefaultSetEdit : TeacherBasePage
    {
        public string act;
        public int id;

        public ExamDefaultModel model = new ExamDefaultModel();

        public string valueArr;
        public string valueArr_re;
        public string targetArr;

        public Dictionary<int, string> categoryList;

        protected override void ShowPage()
        {
            id = XRequest.GetInt("id", -1);
            act = XRequest.GetString("act");
            //act = "n";
         
            ExamBLL bll = new ExamBLL();
            
            categoryList = (new QuestionBLL()).GetQuestionCategoryList();

            StringBuilder sb = new StringBuilder();

            
            if (ispost)
            {

                string title = XRequest.GetString("TitleTxt");
                ExamDefaultModel setting = GetSetting();


                int rst = 0;
                string href = "";

                switch (act)
                {
                    case "n":
                        rst = bll.AddExamDefault(setting);

                        href = "ExamDefaultSetEdit.aspx?act=n";
                        break;
                    case "u":
                        model.id = id;
                        rst = bll.UpdateExamDefault(setting);
                        href = "ExamDefaultSetEdit.aspx?act=u&id=" + id;
                        break;
                    default: break;
                }

                if (rst > 0)
                {
                    Alert("操作成功");
                }
                else
                {
                    Alert("操作失败");
                }
                ExecuteJS("window.location = '" + href + "';");
            }
            else
            {
                if (id != -1)
                {
                    model = bll.GetExamDefaultByID(id);
                    targetArr = model.CategoryIDArr;
                    valueArr = model.QuestionQuantityArr;
                    valueArr_re = model.RequiredQuestionQuantityArr;
                }
            }
        }

        private void SetSetting(ExamDefaultModel m)
        { 

        }

        private ExamDefaultModel GetSetting()
        {
            string category = XRequest.GetString("categoryvalue");
            //string id = XRequest.GetString("coursevalue");
            string input = XRequest.GetString("inputvalue");
            string input_re = XRequest.GetString("inputvalue_re");
            string name = XRequest.GetString("TitleTxt");
            ExamDefaultModel data = new ExamDefaultModel();

            if (!category.Equals("") && !input.Equals("") && !input_re.Equals(""))
            {
                if (act == "u")
                {
                    data.id = id;
                }
                data.CategoryIDArr = category;
                data.DefaultName = name;
                data.QuestionQuantityArr = input;
                data.RequiredQuestionQuantityArr = input_re;
            }
            return data;

        }

        protected void Page_Load(object sender, EventArgs e)
        {

        }
    }
}